<?php

namespace App\Http\Middleware;

use App\Helpers\Token;
use App\Http\Controllers\Controller;
use Closure;
use Illuminate\Http\Request;

class CheckLogin extends Controller
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $data=$request->all();
        $res=Token::verifyToken($data['jwtToken']);
        if($res != 0){
            $request->id=$res;
            return $next($request);
        }
        return parent::error('请先登录再操作',[]);
    }
}
